package com.netintech.project.monitor.controller;

import java.util.List;

import com.netintech.project.monitor.domain.dto.SysOperLogDto;
import com.netintech.project.monitor.service.SysOperLogService;
import com.netintech.project.system.domain.dto.CommonsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.netintech.common.utils.poi.ExcelUtil;
import com.netintech.core.aspectj.lang.annotation.Log;
import com.netintech.core.aspectj.lang.enums.BusinessType;
import com.netintech.core.web.controller.BaseController;
import com.netintech.core.web.domain.RequestResult;
import com.netintech.project.monitor.domain.SysOperLog;

/**
 * 操作日志记录
 *
 * @author admin
 */
@RestController
@RequestMapping("monitor/operlog")
public class SysOperlogController extends BaseController {
    @Autowired
    private SysOperLogService operLogService;

    //    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @RequestMapping("index")
    public RequestResult list(@RequestBody SysOperLogDto operLogDto) {
        return RequestResult.success(operLogService.queryOperLogPage(operLogDto));
    }

    //    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @RequestMapping("export")
    public RequestResult export(@RequestBody SysOperLog operLog) {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        return util.exportExcel(list, "操作日志");
    }

    //    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @RequestMapping("deleteBatch")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    public RequestResult deleteBatch(@RequestBody CommonsDto commonsDto) {
        Long[] ids = commonsDto.getIds();
        if (ids == null || ids.length == 0) {
            return RequestResult.error("ids为空");
        }
        return returnResult(operLogService.deleteOperLogByIds(ids));
    }

    @RequestMapping("delete")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    public RequestResult remove(@RequestBody CommonsDto commonsDto) {
        Long id = commonsDto.getId();
        if (id == null ) {
            return RequestResult.error("id为null");
        }
        return returnResult(operLogService.deleteOperLogById(id));
    }

    //    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @RequestMapping("clean")
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    public RequestResult clean() {
        operLogService.cleanOperLog();
        return RequestResult.success();
    }
}
